<?php
/**
 * Created by PhpStorm.
 * User: zg
 * Date: 18-8-6
 * Time: 下午4:11
 */

namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;
use app\common\model\Questiontype;
use app\common\model\AreaManager;
use app\common\model\AreaItems;
class Base extends Controller
{
    public function _initialize()
    {
        $qM = new Questiontype();

        $list=$qM->with('Questionitems')->order('sort ASC')->select();
        $this->assign('qu',$list);

        $info = Db::name('info')->where('id',1)->find(); //网站信息

        $link = Db::name('link')->where([
            'isDelete' => 0,
            'status' => 1,
        ])->select();


        //获取菜单节点
        $this->assign('M',$this->tree());

        $columns = Db::name('foot')->where(['status'=>1])->order('sort desc,id desc')->select();
        $tree = new \Tree(['flat'=>false]);
        $columns = $tree->getTree($columns);
        $this->assign('info',$info);

        $this->assign('link',$link);

        $this->assign('footmenu',$columns);

        if(\think\Request::instance()->isMobile()){
            $this->view->engine->config('view_path',APP_PATH.'index/view/WAP/');
        }

        parent::_initialize();
    }


    //获取树节点
    public function tree()
    {
        //获取数据集
        $data = Db::query("select * from tp_product where status=1 order by sort asc");


        //获取置顶的选项
        $top = Db::query("select * from tp_product where status=1 and is_nav=1 order by sort asc");

        return ['nav'=> $top,'menu'=>(new \Tree())->getTree($data)];
    }
}